import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { I18nService } from './core/i18n/i18n.service';
import { Title } from '@angular/platform-browser';
import { NzI18nService, zh_CN, ja_JP, en_US } from 'ng-zorro-antd';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit, OnDestroy {
  private subscriptions: Subscription[];

  

  constructor(
    private i18n:I18nService,
    private title:Title,
    private nzI18n:NzI18nService
  ) {
    this.subscriptions = [];
    const lang = localStorage.getItem('lang');
    this.i18n.changeLang(lang ||'zh');
    switch(lang){
			case 'zh':
				this.nzI18n.setLocale(zh_CN);
				break;
			case 'jp':
				this.nzI18n.setLocale(ja_JP);
				break;
			case 'en':
				this.nzI18n.setLocale(en_US);
        break;
      default:
        this.nzI18n.setLocale(zh_CN);
		}
    this.i18n.get('title').subscribe(res=>this.title.setTitle(res));
  };
  ngOnInit() {
  };
  ngOnDestroy(): void {
    if (this.subscriptions && this.subscriptions.length) {
      this.subscriptions.forEach(subscription => subscription.unsubscribe);
    }
    this.subscriptions = [];
  }
}
